************** Replication code for analyses in the manuscript **************

* Title: "Electoral Systems and Gender Inequality in Political News: 
		*Analyzing the News Visibility of Members of Parliament in Norway and the UK"
* Journal: American Political Science Review
* Authors: Gunnar Thesen and Tevfik Murat Yildirim



********************************************************************************
*** Figure 1 *******************************************************************

*** open data from world development indicator
use "data figure 1 world development indicator.dta", clear

*** Create figure 1
line UK Year, lcolor(gs0) || line Norway Year, lcolor(gs10) xtitle("") ytitle("Share of women MPs") ///
graphregion(fcolor(white)) ylabel(0(5)45) legend(region(style(none))) ///
name(Figure1, replace)
graph export "Tables and figures\Figure1.tif", as(tif) replace
********************************************************************************
********************************************************************************




********************************************************************************
*** Descriptives in Table A1, and Table 1 and 2 ********************************

*** open quarterly data uk
use "quarterly data uk.dta", clear
tsset actor qdate

*** Table A1, Appendix A, UK results
tabstat newscount fem age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	, statistics (mean sd min max sum) columns(statistics)
	
*** Table 1, UK results
tabstat newscount legspeech mp_exp /// 
	, by(fem) statistics (sum) 

*** Table 2, UK results
tabstat newscount legspeech mp_exp /// 
	, by(fem) statistics (mean)


*** open quarterly data norway
use "quarterly data norway.dta", clear
tsset actor qdate

*** Table A1, Appendix A, Norwegian results
tabstat newscount fem age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc const_size /// district characteristics
	, statistics (mean sd min max sum) columns(statistics)

*** Table 1, Norwegian results
tabstat newscount legspeech mp_exp /// 
	, by(fem) statistics (sum) 

*** Table 2, Norwegian results
tabstat newscount legspeech mp_exp /// 
	, by(fem) statistics (mean)
********************************************************************************
********************************************************************************


	
	
********************************************************************************
*** Regression models of news visibility in Table 3 ****************************
	
*** open quarterly data uk
use "quarterly data uk.dta", clear
tsset actor qdate
	
*** stepwise multilevel negative binomial, UK results
menbreg newscount i.fem c.age##c.age /// gender and age
	|| actor:
estimates store Tab3UKm1
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	|| actor:
estimates store Tab3UKm2
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	|| actor:
estimates store Tab3UKm3
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	|| actor: 
estimates store Tab3UKm4
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	|| actor: 
estimates store Tab3UKm5

	
*** open quarterly data norway
use "quarterly data norway.dta", clear
tsset actor qdate

*** stepwise multilevel negative binomial, Norwegian results
menbreg newscount i.fem c.age##c.age /// gender and age
	|| actor:
estimates store Tab3NOm1
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	|| actor: 
estimates store Tab3NOm2
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	|| actor: 
estimates store Tab3NOm3
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	|| actor: 
estimates store Tab3NOm4
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	|| actor: 
estimates store Tab3NOm5


*** Export output for table 3
estout Tab3UKm1 Tab3UKm2 Tab3UKm3 Tab3UKm4 Tab3UKm5 Tab3NOm1 Tab3NOm2 Tab3NOm3 Tab3NOm4 Tab3NOm5 using "Tables and figures\Tab3.txt", ///
	replace nobaselevels cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
    stats(N ll, fmt(0 0) label(N Loglikelihood)) style(tab)

********************************************************************************
********************************************************************************




********************************************************************************
*** Predicted news visibility by gender in Table 4 *****************************

*** open quarterly data uk
use "quarterly data uk.dta", clear
tsset actor qdate

*** run full model quietly
quietly menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	|| actor: 

*** Table 4, UK results
margins i.fem, atmeans
margins, dydx(i.fem) atmeans


*** open quarterly data norway
use "quarterly data norway.dta", clear
tsset actor qdate

* run full model quietly
quietly menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	|| actor: 

*** Table 4, Norwegian results
margins i.fem, atmeans
margins, dydx(i.fem) atmeans
********************************************************************************
********************************************************************************




********************************************************************************
*** Interaction results, Table A2 and A3, Appendix A, and Fig 2 and 3 **********

*** open quarterly data uk
use "quarterly data uk.dta", clear
tsset actor qdate

*** Table A2, Appendix A, UK results for gender X distance interaction
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate c.distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.fem#c.distance ///
	|| actor:
estimates store TabA2UK

*** Figure 2, UK results for gender X distance interaction
margins, at(distance =(0(0.2) 1) fem=(0 1) ) level(90) atmeans
marginsplot, xlabel(0(0.1)1)recast(line) recastci(rline) plotopts(lpattern(solid)) ciopts(lpattern(dash)) plot1opts(lcolor(gs0)) plot2opts(lcolor(gs10)) ci1opts(lcolor(gs0)) ci2opts(lcolor(gs10)) ///
ylabel(0(3)24) xtitle(Relative distance to capital) ytitle("") title("") scheme(s1mono)  graphregion(fcolor(white) ///
ifcolor(white)) name(Figure2, replace) allsimplelabels legend(region(style(none)))
graph export "Tables and figures\Figure2.tif", as(tif) replace


*** open quarterly data norway
use "quarterly data norway.dta", clear
tsset actor qdate

*** Table A2, Appendix A, Norwegian results for gender X district size interaction
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	c.const_size i.fem#c.const_size ///
	|| actor:
estimates store TabA2NO

*** Figure 3, Norwegian results for gender X district size interaction
margins, at(const_size=(4 (1) 19) fem=(0 1) ) level(90) atmeans
marginsplot, xlabel(4(1)19)recast(line) recastci(rline) plotopts(lpattern(solid)) ciopts(lpattern(dash)) plot1opts(lcolor(gs0)) plot2opts(lcolor(gs10)) ci1opts(lcolor(gs0)) ci2opts(lcolor(gs10)) ///
ylabel(0(5)40) xtitle(District size (in seats)) ytitle("") title("") scheme(s1mono)  graphregion(fcolor(white) ///
ifcolor(white)) name(Figure3, replace) allsimplelabels legend(region(style(none)))
graph export "Tables and figures\Figure3.tif", as(tif) replace


*** Export output for table A2, Appendix A
estout TabA2UK TabA2NO using "Tables and figures\TabA2.txt", ///
	replace nobaselevels cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
    stats(N ll, fmt(0 0) label(N Loglikelihood)) style(tab)


*** Table A3, Appendix A, marginal effect cited in footnote 14
margins fem, dydx(const_size) 
********************************************************************************
********************************************************************************




********************************************************************************
*** Jack-knife + retest of interaction model, Table A4, Figure A1 **************

*** open quarterly data norway
use "quarterly data norway.dta", clear
tsset actor qdate

*** jackknife of interaction gender X district size, Norway 
gen interaction = const_size * fem
jackknife, cluster(county_no fem) idcluster(newclus) keep: menbreg newscount fem c.age##c.age electoral_safety legspeech mp_exp seat_share cabinet_party party_extremity share_of_parliament cabinet_right distance turnout_perc qdate electionperiod months_from_election comt_leader comt_hard const_size interaction || actor: 
assert e(N_misreps)==0
local N = e(N_clust)
gen dfbeta_interaction = (newscount_b_interaction - _b[interaction])/(`N'-1)
scatter dfbeta_interaction county_no, by(fem) mlabel(county_no) ///
       title("") xtitle("County idno") 
* 4 observations stand out as influential, county-fem: county1-female ,county2-male, county2-female and county11-male

*** Retesting interaction model without these observations, Table A4
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	c.const_size i.fem#c.const_size ///
	if !((county_no ==1 & fem ==1) | (county_no ==11 & fem ==0) | (county_no==2)) ///
	|| actor: 
estimates store TabA4

*** Export output for table A4, Appendix A
estout TabA4 using "Tables and figures\TabA4.txt", ///
	replace nobaselevels cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
    stats(N ll, fmt(0 0) label(N Loglikelihood)) style(tab)


*** Figure A1, gender X district size interaction results without influential obs
margins, at(const_size=(4 (1) 19) fem=(0 1) ) level(90) atmeans
marginsplot, xlabel(4(1)19)recast(line) recastci(rline) plotopts(lpattern(solid)) ciopts(lpattern(dash)) plot1opts(lcolor(gs0)) plot2opts(lcolor(gs10)) ci1opts(lcolor(gs0)) ci2opts(lcolor(gs10)) ///
ylabel(0(5)40) xtitle(District size (in seats)) ytitle("") title("Norway") scheme(s1mono)  graphregion(fcolor(white) ///
ifcolor(white)) name(FigureA1, replace) allsimplelabels legend(region(style(none)))
graph save "Tables and figures\FigureA1.tif", replace
********************************************************************************
********************************************************************************




********************************************************************************
*** Alternative model specifications, Table A5, Appendix A**********************

*** open quarterly data uk
use "quarterly data uk.dta", clear
tsset actor qdate

*** Main model, Table A5, UK results
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	|| actor: 
estimates store TabA5UK1
*** AR term, Table A5, UK results
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	l_newscount /// lagged DV
	|| actor: 
estimates store TabA5UK2
*** Robust vce, Table A5, UK results
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	|| actor: , vce(robust) 
estimates store TabA5UK3


*** open quarterly data norway
use "quarterly data norway.dta", clear
tsset actor qdate

*** Main model, Table A5, Norwegian results
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	|| actor: 
estimates store TabA5NO1
*** AR term, Table A5, Norwegian results
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	l_newscount /// lagged DV
	|| actor: 
estimates store TabA5NO2
*** Robust vce, Table A5, Norwegian results
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	|| actor: , vce(robust)
estimates store TabA5NO3

*** Export output for table A4, Appendix A
estout TabA5UK1 TabA5UK2 TabA5UK3 TabA5NO1 TabA5NO2 TabA5NO3 using "Tables and figures\TabA5.txt", ///
	replace nobaselevels cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
    stats(N ll, fmt(0 0) label(N Loglikelihood)) style(tab)

********************************************************************************
********************************************************************************




********************************************************************************
*** Pooled model, Table A6 and A7, Appendix A **********************************

*** combine quarterly data
use "quarterly data norway.dta", clear
drop county comt_hard electoral_safety county_no const_size comt_leader l_newscount party_id
gen UK_dummy = 0
decode actor, generate(actor_str)
drop actor
save "pooled quarterly data norway uk.dta", replace

use "quarterly data uk.dta", clear
drop electoral_safety l_newscount party_id
gen UK_dummy =1
decode actor, generate(actor_str)
drop actor

append using "pooled quarterly data norway uk.dta"
save "pooled quarterly data norway uk.dta", replace

*** open pooled quarterly data norway and uk
use "pooled quarterly data norway uk.dta", clear
encode actor_str, gen(actor_enc)
drop actor_str

*** Pooled model, Table A6
tsset actor_enc qdate
menbreg newscount i.fem c.age##c.age /// gender and age
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	qdate electionperiod months_from_election /// time
	i.UK_dummy i.fem#i.UK_dummy ///
	|| actor: 
estimates store TabA6

*** Export output for table A4, Appendix A
estout TabA6 using "Tables and figures\TabA6.txt", ///
	replace nobaselevels cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
    stats(N ll, fmt(0 0) label(N Loglikelihood)) style(tab)

*** Predicted news visibility after pooled model, Table A7
margins, at(UK_dummy=(0 1) fem=(0 1)) atmeans
margins UK_dummy, dydx(fem) atmeans
********************************************************************************
********************************************************************************




********************************************************************************
*** Models with monthly / annual observations, Table A8, Appendix A ************

*** open monthly data uk
use "monthly data uk.dta", clear
tsset actor yearmonth

*** Monthly results UK, Table A8
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	yearmonth electionperiod months_from_election /// time
	|| actor: 
estimates store TabA8UKmonths

*** Aggregate to yearly data, uk
collapse (sum) newscount legspeech (max) fem mp_exp electoral_safety ///
	seat_share age cabinet_party party_extremity share_of_parliament cabinet_right ///
	electorate distance turnout_perc /// 
	electionperiod months_from_election /// 
	, by(actor year)

tsset actor year

*** Yearly results UK, Table A8
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	year electionperiod months_from_election /// time
	|| actor: 
estimates store TabA8UKyears

*** open monthly data norway
use "monthly data norway.dta", clear
tsset actor yearmonth

*** Monthly results norway, Table A8
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	yearmonth electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	|| actor:
estimates store TabA8NOmonths

*** Aggregate to yearly data, norway
collapse (sum) newscount legspeech (max) fem mp_exp electoral_safety ///
	seat_share age cabinet_party party_extremity share_of_parliament cabinet_right ///
	electorate distance turnout_perc /// 
	electionperiod months_from_election /// 
	comt_leader comt_hard ///
	, by(actor year)

tsset actor year

*** Yearly results Norway, Table A8
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	year electionperiod months_from_election /// time
	i.comt_leader i.comt_hard ///
	|| actor: 
estimates store TabA8NOyears

*** Export output for table A8, Appendix A
estout TabA8UKmonths TabA8UKyears TabA8NOmonths TabA8NOyears using "Tables and figures\TabA8.txt", ///
	replace nobaselevels cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
    stats(N ll, fmt(0 0) label(N Loglikelihood)) style(tab)

********************************************************************************
********************************************************************************




********************************************************************************
*** Models with routine times and election periods, Table A9, Appendix A *******

*** open monthly data uk
use "monthly data uk.dta", replace
tsset actor yearmonth

*** routine times model, Table A9
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate c.distance turnout_perc /// district characteristics
	yearmonth months_from_election /// time
	if electionperiod==0 ///
	|| actor:
estimates store TabA9UKroutine

*** election period model, Table A9
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	legspeech /// legislative speeches
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate c.distance turnout_perc /// district characteristics
	yearmonth /// time
	if electionperiod==1 ///
	|| actor:
estimates store TabA9UKelection

*** open monthly data norway including September (election month)
use "monthly data norway incl legspeechNAs.dta", replace
tsset actor yearmonth

*** routine times model, Table A9
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	yearmonth months_from_election /// time
	i.comt_leader i.comt_hard ///
	if electionperiod==0 ///
	|| actor:
estimates store TabA9NOroutine

*** election period model, Table A9
menbreg newscount i.fem c.age##c.age /// gender and age
	electoral_safety /// electoral safety 
	mp_exp /// experience
	seat_share cabinet_party party_extremity share_of_parliament cabinet_right /// party characteristics + government size and color
	electorate distance turnout_perc /// district characteristics
	yearmonth /// time
	i.comt_leader i.comt_hard ///
	if electionperiod==1 ///
	|| actor:
estimates store TabA9NOelection

*** Export output for table A9, Appendix A
estout TabA9UKroutine TabA9UKelection TabA9NOroutine TabA9NOelection using "Tables and figures\TabA9.txt", ///
	replace nobaselevels cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) ///
    stats(N ll, fmt(0 0) label(N Loglikelihood)) style(tab)
********************************************************************************
********************************************************************************

